package tabelahorario;

import java.util.ArrayList;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import br.com.sistransporte.transite.diasemana.controller.DiaSemanaFacade;
import br.com.sistransporte.transite.evento.controller.EventoFacade;
import br.com.sistransporte.transite.horario.controller.HorarioFacade;
import br.com.sistransporte.transite.tabelahorario.controller.TabelaHorarioFacade;
import br.com.sistransporte.transitedto.diasemana.DiaSemanaDTO;
import br.com.sistransporte.transitedto.evento.EventoDTO;
import br.com.sistransporte.transitedto.horario.HorarioDTO;
import br.com.sistransporte.transitedto.tabelahorario.TabelaHorarioDTO;
import br.com.src.dto.abstractdto.AbstractDTO;
import br.com.src.dto.requisicao_retorno.RequisicaoServico;
import br.com.src.dto.requisicao_retorno.RetornoServico;
import br.com.src.utilidades.Utilidades;

/**
 * 
 * Classe que representa
 *
 *
 * @author Nelson Luis da Silva Junior <nelson.jr13@hotmail.com>
 * @since 18 de Set de 2013 02:43:00
 * @version 1.0
 */
@ContextConfiguration( locations = { "classpath:rootTeste-context.xml", "classpath:rootTesteLog-context.xml" } )
@RunWith( SpringJUnit4ClassRunner.class )
public final class TabelaHorarioTeste{

	//@Test
	public void filtrar() throws Throwable {
		RequisicaoServico requisicaoServico = new RequisicaoServico( "teste", new TabelaHorarioDTO() );
		RetornoServico retornoServico = TabelaHorarioFacade.getInstance().filtrar(requisicaoServico);

		if ( !Utilidades.isNuloOuVazio( retornoServico.erro ) ) {
			throw retornoServico.erro;
		}

		for ( AbstractDTO abstractsDTOs : retornoServico.getDtosRetorno() ) {
			System.out.println( abstractsDTOs );
		}
	}

	@Test
	public void inserir() throws Throwable{
		RequisicaoServico requisicaoServicoEvento = new RequisicaoServico( "nelson" , new EventoDTO( "1" ));
		RetornoServico retornoServicoEvento = EventoFacade.getInstance().filtrar( requisicaoServicoEvento );
		
		EventoDTO evento = (EventoDTO) retornoServicoEvento.getSingleDTO();
		
		RequisicaoServico requisicaoServicoHorario = new RequisicaoServico( "nelson" , new HorarioDTO( "1" ));
		RetornoServico retornoServicoLoc = HorarioFacade.getInstance().filtrar( requisicaoServicoHorario );
		
		HorarioDTO horario = (HorarioDTO) retornoServicoLoc.getSingleDTO();
		ArrayList< HorarioDTO > listaHorarios = new ArrayList< HorarioDTO >();
		listaHorarios.add( horario );
		
		RequisicaoServico requisicaoServicoDia = new RequisicaoServico( "nelson" , new DiaSemanaDTO( "1" ));
		RetornoServico retornoServicoDia = DiaSemanaFacade.getInstance().filtrar( requisicaoServicoDia );
		
		DiaSemanaDTO dia = (DiaSemanaDTO) retornoServicoDia.getSingleDTO();
		
		RequisicaoServico requisicaoServico = new RequisicaoServico( "nelson" , new TabelaHorarioDTO( null, dia,listaHorarios,evento));
		RetornoServico retornoServico = TabelaHorarioFacade.getInstance().inserir( requisicaoServico );

		filtrar();

		if( !Utilidades.isNuloOuVazio( retornoServico.erro )){
			throw retornoServico.erro;
		}
	}

	@Ignore
	public void alterar() throws Throwable{
		RequisicaoServico requisicaoServico = new RequisicaoServico( "nelson" , new TabelaHorarioDTO("1",null,null,null));
		RetornoServico retornoServico = TabelaHorarioFacade.getInstance().alterar( requisicaoServico );

		filtrar();

		if( !Utilidades.isNuloOuVazio( retornoServico.erro )){
			throw retornoServico.erro;
		}
	}

	@Ignore
	public void delete() throws Throwable{
		// Consultando
		RequisicaoServico requisicaoServicoFilter = new RequisicaoServico( "teste", new TabelaHorarioDTO("3") );
		RetornoServico retornoServicoFilter = TabelaHorarioFacade.getInstance().filtrar( requisicaoServicoFilter );
		if ( !Utilidades.isNuloOuVazio( retornoServicoFilter.erro ) ) {
			throw retornoServicoFilter.erro;
		}
		for ( AbstractDTO abstractsDTOs : retornoServicoFilter.getDtosRetorno() ) {
			System.out.println( abstractsDTOs );
		}
		
		
		RequisicaoServico requisicaoServico = new RequisicaoServico( "gabriel" , retornoServicoFilter.getSingleDTO() );
		RetornoServico retornoServico = TabelaHorarioFacade.getInstance().excluir( requisicaoServico );

		filtrar();

		if( !Utilidades.isNuloOuVazio( retornoServico.erro )){
			throw retornoServico.erro;
		}
	}

	
}
